home *** CD-ROM | disk | FTP | other *** search
- Path: colossus.holonet.net!russell
- From: russell@news.mdli.com (Russell Blackadar)
- Newsgroups: comp.lang.c++
- Subject: Re: why is dat ?
- Date: 30 Jan 1996 08:59:36 GMT
- Organization: HoloNet National Internet Access System: 510-704-1058/modem
- Message-ID: <4ekmlo$k7f@colossus.holonet.net>
- References: <310DCC58.798E@pergamon.isar.de>
- NNTP-Posting-Host: jubal.mdli.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Gerson Kurz (dekonstruktor@pergamon.isar.de) wrote:
- : hi guys, this is my first msg here so I don't know if this has
- : been answered 10^50 times before but here it goes:
-
- : class A {};
- : class B : public A {};
-
- : B* pointer_to_B;
- : A** pointer_to_pointer_to_A = &pointer_to_B;
-
- This is an unsafe conversion. Suppose you wrote the above,
- and then wrote the following two statememts:
-
- *pointer_to_pointer_to_A = new A; // looks reasonable, eh? but we
- // change pointer_to_B, so now it
- pointer_to_B->some_B_member(); // CRASH! points to an A, not a B
-
- Therefore, the automatic conversion must not be allowed. You can go
- from B* to A*, but not B** to A**.
- --
- Russell Blackadar, russell@mdli.com
-